package br.ufla.pgcc.oomeasures.astvisitors;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class AttributeHidingFactorVisitor extends ASTVisitor{

	private double attributeHidingFactorIndex;
	
	@Override
	public boolean visit(CompilationUnit unit) {

		calculateAttributeHidingFactor(unit);

		return super.visit(unit);
	}
	
	/**
	 * The MHF is calculated by [sum(AV) / Number of attributes],
	 * where AV is number of other classes where attribute is visible.
	 */
	private void calculateAttributeHidingFactor(CompilationUnit unit){
		
		BigDecimal numPrivateAttributes = new BigDecimal(AttributeVisitor.getNumberOfProjectPrivateAttributes());
		BigDecimal numClasses = new BigDecimal(ClassVisitor.getNumOfProjectClasses());
		BigDecimal numAttributes = new BigDecimal(AttributeVisitor.getNumberOfProjectAttributes());
		
		BigDecimal numerator = numPrivateAttributes.divide(numClasses, 2, RoundingMode.UP);
		
		attributeHidingFactorIndex = numerator.divide(numAttributes, 2, RoundingMode.UP).doubleValue();
		
	}
	
	public double getAttributeHidingFactor(){
		return attributeHidingFactorIndex;
	}
	
}
